package com.jhg.drgclinicalpathway.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jhg.drgclinicalpathway.domain.LJ临床路径版本;
import com.jhg.drgclinicalpathway.domain.V临床路径项目;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface LJ临床路径版本Dao extends BaseMapper<LJ临床路径版本> {


    @Select({
            "<script>",
            "select b.*,a.场合 from LJ_临床路径版本 a left join LJ_临床路径目录 b on a.路径ID=b.ID",
            " where a.ID=#{id}",
            "</script>",
    })
    public Map<String,Object> ljInfo(@Param("id") String id);

    @Select({
            "select * from LJ_临床路径版本 where 路径ID=#{pid} and 场合=#{t}"
    })
    public List<Map<String,Object>>checkLJ临床路径版本(@Param("pid") Integer pid,@Param("t") Integer t);

    @Select({
            "<script>",
            "select top 50 * from V临床路径目录 where 名称 like '%${s}%' or 拼音简码 like '${s}%'",
            "</script>",
    })
    public List<Map<String,Object>> V临床路径目录(String s);

    @Select({
            "<script>",
            "SELECT BR.路径ID,BR.路径名称,XM.住院医师,XM.项目ID,XM.项目名称,BR.病人例数,XM.项目例数,XM.范围,CONVERT(DECIMAL(18,2),(XM.项目例数 + 0.00) / (BR.病人例数 + 0.00)) 项目使用占比 FROM (",
            "SELECT 路径ID,路径名称,住院医师,COUNT(DISTINCT 病人标识) 病人例数",
            "FROM DBO.VDCP_病人路径评估_住院医师 WHERE 出院日期 BETWEEN #{stime} AND #{etime}",
            "AND 项目类型=#{ts}",
            "AND 路径名称 like '%${lw}%'",
            " <if test=\"docs != null and docs.size() > 0 \">",
            " and 住院医师 in",
            "<foreach collection='docs' open='(' close=')' item='id' index='i' separator=','>",
            "#{id}",
            "</foreach>",
            "</if>",
            "GROUP BY 路径ID,路径名称,住院医师) BR JOIN (",
            "SELECT 路径ID,住院医师,项目ID,项目名称,范围,COUNT(1) 项目例数",
            "FROM DBO.VDCP_病人路径评估_住院医师 WHERE 出院日期 BETWEEN #{stime} AND  #{etime}",
            "AND 项目类型=#{ts}",
            "AND 路径名称 like '%${lw}%'",
            " <if test=\"docs != null and docs.size() > 0 \">",
            " and 住院医师 in",
            "<foreach collection='docs' open='(' close=')' item='id' index='i' separator=','>",
            "#{id}",
            "</foreach>",
            "</if>",
            "GROUP BY 路径ID,住院医师,项目ID,项目名称,范围) XM ON BR.路径ID = XM.路径ID AND BR.住院医师=XM.住院医师",
            "WHERE (XM.项目例数 + 0.00) / (BR.病人例数 + 0.00) &gt; ${r}",

            "</script>",
    })
    public List<Map<String,Object>> 项目对比(@Param("stime") String stime,
                                         @Param("etime") String etime,
                                         @Param("docs") List<String> docs,
                                         @Param("ts") String ts,
                                         @Param("lw") String lw,
                                         @Param("r") double r
                                         );


    @Select({
            "<script>",
            "exec PRO_病人路径评估_项目对比",
            "@开始日期=#{stime},",
            "@结束日期=#{etime},",
            "@住院医师=#{zyys},",
            "@项目类型=#{xmlx},",
            "@条件类别=#{tjlb},",
            "@条件描述=#{tjms},",
            "@比例限制=#{blxz}",
            "</script>"
    })
    public List<Map<String,Object>> 项目对比2(@Param("stime") String stime,
                                          @Param("etime") String etime,
                                          @Param("zyys") String zyys,
                                          @Param("xmlx") String xmlx,
                                          @Param("tjlb") String tjlb,
                                          @Param("tjms") String tjms,
                                          @Param("blxz") Double blxz
                                          );

    @Select({"<script>" ,
            "select * from V临床路径项目 where id=#{xmid}",
            "</script>"})
    public  List<V临床路径项目> getljxm(@Param("xmid") String xmid);
}
